package com.gitee.feizns.explore.data_structure.stack;

/**
 * @author feizns
 * @since 2020/3/24
 */
public class NumSquares {

    public static void main(String[] args) {
        System.out.println(numSquares(12));
    }

    static int ans = 0;

    public static int numSquares(int n) {
        helper(n, 1);
        return ans;
    }

    private static int helper(int n, int d) {
        int x = d * d;
        if ( x > n )
            return n;
        int newN = helper(n, d + 1);
        while ( newN >= x ) {
            ans++;
            newN -= x;
        }
        return newN;
    }

}
